<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <title>寝室管理后台首页</title>
    <link rel="stylesheet" type="text/css"  href="/DMS/PHP-DMS/lib/jeasyui/1.7.5/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="/DMS/PHP-DMS/lib/jeasyui/1.7.5/themes/icon.css">
    <script type="text/javascript"  src="/DMS/PHP-DMS/lib/jquery/1.12.4/jquery.min.js"></script>
    <script type="text/javascript"  src="/DMS/PHP-DMS/lib/jeasyui/1.7.5/jquery.easyui.min.js"></script>
</head>
<body >

<table class="easyui-datagrid" style="width:94%" id="td"
       data-options="rownumbers:true,singleSelect:true,url:'/DMS/PHP-DMS/controller/getAllstudents.php',method:'get',toolbar:toolbar">
    <thead>
    <tr >
        <th data-options="field:'name'" style="width: 14%;text-align: center">姓名</th>
        <th data-options="field:'sex'" style="width: 14%;text-align:center">性别</th>
        <th data-options="field:'age',align:'right'" style="width: 14%;text-align: center">年龄</th>
        <th data-options="field:'dormitorynumber',align:'right'" style="width: 14%;text-align: center">宿舍号</th>
        <th data-options="field:'college'" style="width: 14%;text-align: center">学院</th>
        <th data-options="field:'profession',align:'center'" style="width: 14%;text-align: center">专业</th>
        <th data-options="field:'class'" style="width: 14%;text-align: center">班级</th>
    </tr>
    </thead>
</table>
<div id="win" class="easyui-window" title="添加学生" style="width:700px;height:500px"
data-options="iconCls:'icon-save',closed:true,minimizable:false,maximizable:false,collapsible:false">
    <form id="ff" method="post">
        <table cellpadding="5" style="margin-left: 200px">
            <tr>
                <td>姓名:</td>
                <td><input class="easyui-textbox" type="text" name="name" data-options="required:true,validType:'minLength[5]'"></input></td>
            </tr>
            <tr>
                <td>性别:</td>
                <td><input class="easyui-textbox" type="text" name="sex" data-options="required:true"></input></td>
            </tr>
            <tr>
                <td>年龄:</td>
                <td><input class="easyui-textbox" type="text" name="age" data-options="required:true"></input></td>
            </tr>
            <tr>
                <td>宿舍号:</td>
                <td><input class="easyui-textbox" name="dormitorynumber" data-options="multiline:true" ></input></td>
            </tr>
            <tr>
            <td>学院:</td>
            <td>
                <select id="department" class=" form-control-static" name="college">
                    <option name="college" value="-1">---------学院---------</option>
                </select>
            </td>
            </tr>
            <tr>
                <td>专业:</td>
                <td>
                    <select id="major" class="form-control-static" name="profession">
                        <option name="profession" value="-1">---------专业---------</option>
                    </select>  </td>
            </tr>
            <tr>
                <td>班级:</td>
                <td>
                    <select id="classes" class="form-control-static" name="class">
                        <option name="class" value="-1">---------班级---------</option>
                    </select>  </td>
            </tr>
        </table>
    </form>
    <div style="text-align:center;margin-top: 70px">
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()">取消</a>
    </div>
</div>
</div>
<script type="text/javascript">
    $(function() {
        $.ajax({
            url: 'department.xml',
            datatype: 'xml',
            type: 'get',
            async:false,
            success: function (xml) {
                $.each($(xml).find('Department'), function (k, v) {
                    $('#department').append('<option value=' + $(v).attr('ID') + '>' + $(v).attr('departmentName') + '</option>')
                });

            },
        });

    });


    //给院系下拉框绑定change事件
    $('#department').bind('change',Department_Onchange);







    //给专业下拉框绑定change事件
    $('#major').bind('change',Major_Onchange);




    //院系下拉框的change事件,当院系数据发生变化的时候加载专业数据
    function Department_Onchange(){
        $('#classes').empty();
        $('#major').empty();
        $('#major').append($('<option></option>').text("---------专业---------"));var id = $("#department option:selected").val();
        $('#classes').append($('<option></option>').text("---------班级---------"));
        $.ajax({
            url: 'major.xml',
            datatype: 'xml',
            type: 'get',
            success: function (xml) {

                var id =  $("#department option:selected").val();


                $(xml).find("Major").each(function(){
                    var did = $(this).attr('DID');

                    if(id == did){
                        $('#major').append('<option value=' + $(this).attr('ID') + '>' + $(this).attr('majorName') + '</option>')
                    }
                });
            },

            async: false,
        })
        //input your code
    }
    //专业下拉框的change事件,当专业数据发生变化的时候加载班级数据
    function Major_Onchange() {
        $('#classes').empty();
        $('#classes').append($('<option></option>').text("---------班级---------"));
        $.ajax({
            url: 'classes.xml',
            datatype: 'xml',
            type: 'get',
            success: function (xml) {

                var id = $("#major option:selected").val();


                $(xml).find("Class").each(function () {
                    var mid = $(this).attr('mID');

                    if (id == mid) {
                        $('#classes').append('<option value=' + $(this).attr('mid') + '>' + $(this).attr('className') + '</option>')
                    }
                });
            },

            async: false,

        })

    }




    var toolbar = [{

        text:'添加',
        iconCls:'icon-add',
        handler:function(){
            $('#win').window('open'); // open a window


        }

    },{
        text:'修改',
        iconCls:'icon-cut',
        handler:function(){




        }
    },{
        text:'删除',
        iconCls:'icon-save',
        handler:function(){

            alert('save')


        }
    }];

    function submitForm() {
        var options1=$('#department option:selected'); //获取选中的项
        var options2=$('#major option:selected'); //获取选中的项
        var options3=$('#classes option:selected'); //获取选中的项

        $('#ff').form('submit', {
            url:"/DMS/PHP-DMS/controller/insertStudent.php",
            onSubmit: function(data){
                data.college=options1.text();
                data.profession=options2.text();
                data.class=options3.text();

            },
            success:function(data){
                var obj = JSON.parse(data);
                $.messager.alert('My Title',obj.msg,function (r) {
                    if (r){
                        $.messager.progress('clear');
                    }

                });


            }
        });

    }
    function clearForm() {
        $('#win').window('close');
        $('#tg').datagrid('reload');
    }


</script>
</body>
</html>